package com.housekeeperapp;

//import com.facebook.react.ReactActivity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

//import com.cboy.rn.splashscreen.SplashScreen;
import com.facebook.react.modules.core.PermissionListener;
import com.housekeeperapp.services.ForegroundService;
import com.reactnativenavigation.controllers.SplashActivity;

import android.widget.LinearLayout;
import android.graphics.Color;
import android.widget.TextView;
import android.view.Gravity;
import android.view.KeyEvent;
import android.util.TypedValue;
import android.widget.Toast;



public class MainActivity extends SplashActivity {

    private PermissionListener listener;

    private static MainActivity instance;

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
//    @Override
//    protected String getMainComponentName() {
//        return "HouseKeeperApp";
//    }

//    @Override
//    public void setPermissionListener(PermissionListener listener)
//    {
//        this.listener = listener;
//    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
    {
        if (listener != null)
        {
            listener.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    @Override
    public LinearLayout createSplashLayout() {
        LinearLayout view = new LinearLayout(this);
//        TextView textView = new TextView(this);

        view.setBackgroundColor(Color.parseColor("#607D8B"));
        view.setBackground(getResources().getDrawable(R.drawable.bg_1242_2208));

        view.setGravity(Gravity.CENTER);

//        textView.setTextColor(Color.parseColor("#FFFFFF"));
//        textView.setText("欢迎");
//        textView.setGravity(Gravity.CENTER);
//        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 40);

//        view.addView(textView);
        return view;
    }

    /**
     * Class Instance Object
     *
     * @return MainActivity
     */
    public static MainActivity getInstance() {
        return instance;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

//        SplashScreen.show(this);
        super.onCreate(savedInstanceState);
        instance = this;
//        JPushInterface.init(this);
        Intent intent = new Intent(this, ForegroundService.class);
        startService(intent);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return false;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onPause() {
        super.onPause();
//        JPushInterface.onPause(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
//        JPushInterface.onResume(this);
    }
}
